package ghr.day0109.lottery.vo;

import ghr.day0109.lottery.dao.UserDao;
import ghr.day0109.lottery.dao.impl.UserDaoimpl;
import ghr.day0109.lottery.entity.UserMark;

import java.util.*;

public class Travel {
    UserDao userDao = new UserDaoimpl();
    public int showAll(){
        List<UserMark> userMarks = userDao.queryAllUser();
        int nums = 0;
        String status;
        System.out.println("姓名\t\t中签编码\t\t持照状态\t\t手机号码\t\t开户日期");
        for (UserMark users : userMarks){
            if (users.getStatus() == 0){
                status = "已持照";

            }else {
                status ="未持照";
                nums++;
            }
            System.out.println(users.getUserName()+"\t\t"+users.getMarkNo()+"\t\t"+status
                    +"\t\t\t"+users.getPhone()+"\t\t"+users.getOpenDate());
        }
        return nums;
    }

    public void showSelect(String select) {
        List<UserMark> userMarks = userDao.queryChooseUser("%"+select+"%");
        UserMark user = null;
        String status;
        System.out.println("姓名\t\t中签编码\t\t持照状态\t\t手机号码\t\t开户日期");
        for (UserMark users : userMarks) {
            if (users.getStatus() == 0) {
                status = "已持照";
            } else {
                status = "未持照";
            }
            System.out.println(users.getUserName()+"\t\t"+users.getMarkNo()+"\t\t"+status
                    +"\t\t\t"+users.getPhone()+"\t\t"+users.getOpenDate());
        }
    }

    public void addUser(String userName,String phone){
        UserMark user = new UserMark();
        user.setUserName(userName);
        user.setPhone(phone);
        UUID uuid = UUID.randomUUID();
        String [] arr = uuid.toString().split("-");
        user.setMarkNo(arr[0]);
        user.setOpenDate("2022-12-26");
        int addRest = userDao.addUser(user);
        System.out.println(addRest > 0 ? "添加成功":"添加失败");
    }

    public void mark(int num){
        List<UserMark> userMarks = userDao.queryAllUser();
        Map<Integer,String> map = new HashMap<>();
        for (UserMark users : userMarks){
            map.put(users.getId(),users.getMarkNo());
        }
        List<Map.Entry<Integer, String>> entries = new ArrayList<>(map.entrySet());
        Collections.shuffle(entries);
        List<Map.Entry<Integer, String>> subList = entries.subList(0, num);
        for (Map.Entry<Integer, String> entry : subList) {
            System.out.println(entry.getValue());
        }
    }
}
